﻿<?
	@require_once("DatabaseExec.php");
	@require_once("Utility.php");

	$type = $_GET['type'];
	
	$name = mysql_real_escape_string(urldecode($_GET['name']));
	
	if(isset($_GET['from']))
		$from = $_GET['from'];
	if(isset($_GET['to']))
		$to = $_GET['to'];
		
	if($type == 'num')
		LoadTypeNum();
	else if($type == 'thumbnail')
		LoadTypeThumbnail();
	else echo "Type Mismatch =$type=";

	function LoadTypeNum()
	{
		$sql = "SELECT count(*) as num FROM userinfo u "
			. CreateCond();
		$rows = ExecSQL($sql);
		
		if($rows)
			echo urlencode($rows[0]);
		else
			echo urlencode("0");
	}
	
	function LoadTypeThumbnail()
	{
		global $name;
		if($name == 'undefined')
			$name = '';
		if(CanSeeAllInfo())
			$field = "t.typeStatusId,t.display,u.profileId,u.name,u.lastname,u.nickName,u.rank,u.`profilePic`";
		else
			$field = "t.typeStatusId,t.display,u.profileId,u.name,u.lastname,u.nickName,'' as rank,u.`profilePic`";
		$sql = "SELECT " . $field . " FROM userinfo u LEFT JOIN `typestatus` t ON u.`typeStatusId`= t.`typeStatusId` "
			. CreateCond() . " ORDER BY u.profileId desc " . Limit();
		
		//echo $sql;
		
		$rs_arry = ExecSQLToArray($sql);
		if(isset($rs_arry))
			echo urlencode(json_encode($rs_arry));
		else
			echo "";
	}
	
	function CreateCond()
	{
		global $name;
	
		$sql = "";
		if($name != '')
			$sql = "u.name like '%$name%' or u.lastname like '%$name%' or u.nickName like '%$name%' ";
		
		if($sql != '')
			$sql = $sql . "and ";
		$sql = $sql . "rowstatus='A' ";
		return " WHERE " . $sql;
	}
	
	function Limit()
	{
		global $from,$to;
		$from = $from - 1;
		$num = $to - $from;		
		return "LIMIT $from,$num ";
	}
?>